package com.ds.lens.data.common.query;

import java.util.concurrent.TimeUnit;

public enum TimeUnitEnum {
    MINUTE('m', TimeUnit.MINUTES),
    HOUR('h', TimeUnit.HOURS),
    DAY('d', TimeUnit.DAYS);

    private char mark;
    private TimeUnit timeUnit;

    TimeUnitEnum(char mark, TimeUnit timeUnit) {
        this.mark = mark;
        this.timeUnit = timeUnit;
    }

    public static TimeUnitEnum get(char mark) {
        if (MINUTE.mark == mark) {
            return MINUTE;
        } else if (HOUR.mark == mark) {
            return HOUR;
        } else if (DAY.mark == mark) {
            return DAY;
        } else {
            return null;
        }
    }

    public long toMills(long duration) {
        if (this == MINUTE) {
            return duration * 60 * 1000;
        } else if (this == HOUR) {
            return duration * 60 * 1000 * 60;
        } else {
            return duration * 60 * 1000 * 60 * 24;
        }
    }

    public long toMinute(long duration) {
        if (this == MINUTE) {
            return duration;
        } else if (this == HOUR) {
            return duration * 60;
        } else {
            return duration * 1440;
        }
    }
}
